#include <atomic>
#include <chrono>
#include <iostream>
#include <string>
#include <sys/epoll.h>
#include <thread>
#include <vector>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>

using namespace std;
using std::string;

using namespace std::chrono_literals;
using namespace std::chrono;

std::string GetFwName(const std::string &pathName)
{
  #if 1
    DIR *dp;
    struct dirent *ep;
  
    dp = opendir(pathName.c_str());
    if (dp == NULL) {
        printf("Could not open directory :<%d>", errno);
        return "";
    }

    while ((ep = readdir(dp))) {
		//printf("%s\n", ep->d_name);
        if (NULL != strstr(ep->d_name,".xpk")) {
            printf("Found FW: <%s>\n", ep->d_name);
            std::string fwName = ep->d_name;
            return fwName;
        }else{
            std::this_thread::sleep_for(std::chrono::milliseconds(1));
        }
    }
#endif 
    return "";
}

int main()
{
	std::string tmpPath = "/home/wangzhijun/work/test";
	std::string fwName = GetFwName(tmpPath);
	if (fwName == "")
	{
		printf("blank\n");
	}
	printf("%s\n", fwName.c_str());
}
